#@adminLayout() #define main()
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="config-form">
					<div class="select-list">
						<ul>
						<input type="hidden" name="code" value="#(code)" />
							<li>流程名称：
							<select name="wfid"  onchange="$.table.search()" id="wfid">
								<option value="all">全部流程</option>
								#for(item:wflist)
								<option value="#(item.id)">#(item.name)</option>
								#end
							</select>
							</li>
							<li>流程描述：<input type="text" name="task_desc"/>
							</li>
							<li id="range">流程状态：
							<select name="status"  onchange="$.table.search()">
								<option value="all">全部</option>
								<option value="1">审批中</option>
								<option value="2">审批完成</option>
								<option value="3">已作废</option>
							</select>
							</li>
							<li>我的流程：
							<select name="wfflag"  onchange="$.table.search()">
								<option value="all">全部流程</option>
								<option value="1">我发起的流程</option>
								<option value="2">我参与的流程</option>
							</select>
							</li>
							<li>
								<label>启动日期： </label>
                                <input type="text" autocomplete="off" id="sdate" name="sdate" placeholder="开始日期"/>
                                <span>到</span>
                                <input type="text" autocomplete="off" id="edate" name="edate" placeholder="结束日期"/>
							</li>
							<li><a class="btn btn-primary btn-rounded btn-sm"
								onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm"
								onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
			</div>
			<div class="col-sm-12 select-table table-bordered">
				<table id="bootstrap-table" data-mobile-responsive="true"
					style="table-layout: fixed; word-break: break-all;"></table>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
	
    var prefix ="#(ctx)/jwflow_task";
    var range='#(range)';
    var code='#(code)';
    var wf_id='#(wf_id)';
    
    $(function() {
		
    	if(code!='all')
    	{
    		$("#wfid option[value='"+wf_id+"'] ").attr("selected", "selected");
    	}
    	if(range=="deal")
		{
			$('#range').hide();
		}
    	
    	layui.use('laydate', function(){
   		   var laydate = layui.laydate;
	 		  var startDate = laydate.render({
		        elem: '#sdate',
		        max: $('#edate').val(),
		        theme: 'molv',
		        trigger: 'click',
		        done: function(value, date) {
		            // 结束时间大于开始时间
		            if (value !== '') {
		                endDate.config.min.year = date.year;
		                endDate.config.min.month = date.month - 1;
		                endDate.config.min.date = date.date;
		            } else {
		                endDate.config.min.year = '';
		                endDate.config.min.month = '';
		                endDate.config.min.date = '';
		            }
		        }
		      });
		      var endDate = laydate.render({
		        elem: '#edate',
		        min: $('#sdate').val(),
		        theme: 'molv',
		        trigger: 'click',
		        done: function(value, date) {
		            // 开始时间小于结束时间
		            if (value !== '') {
		                startDate.config.max.year = date.year;
		                startDate.config.max.month = date.month - 1;
		                startDate.config.max.date = date.date;
		            } else {
		                startDate.config.max.year = '';
		                startDate.config.max.month = '';
		                startDate.config.max.date = '';
		            }
		        }
		      });
		});
		
		if(range=='all')
		{
			$('#li_range').hide();
		}
		
        var options = {
            url: prefix + "/list?range="+range,
		    pageSize: 10,
            uniqueId: "id",
            sortName: "update_time",
            sortOrder: "desc",
            modalName: "流程",
            columns: [{
					title: '序号',//标题  可不加,
                    width:'50px',
                    align: 'center',
					formatter: function (value, row, index) {
						return index+1;
					}
             },
			{
                 field: 'task_name',
                 title: '流程名称',
                 width: '180px',
                 halign:'center',
                 align: 'left',
                 formatter: function(value, row, index) {
                   	return $.table.tooltip(value);
                   },
                 sortable:true //设置库存列可以排序
             },
			{
                 field: 'task_desc',
                 title: '流程描述',
                 width: '200px',
                 halign:'center',
                 align: 'left',
                 formatter: function(value, row, index) {
                   	return $.table.tooltip(value);
                   },
                 sortable:true //设置库存列可以排序
             },
             
			{
                 field: 'node_name',
                 title: '节点',
                 width: '110px',
                 halign:'center',
                 align: 'center',
                 formatter: function(value, row, index) {
                   	return $.table.tooltip(value);
                   },
                 sortable:true //设置库存列可以排序
             },
			{
                 field: 'update_time',
                 title: '时间',
                 width: '130px',
                 halign:'center',
                 sortable:true //设置库存列可以排序
             },
			{
                 field: 'iscancel',
                 title: '作废',
                 width: '80px',
                 align: 'center',
                 sortable:true //设置库存列可以排序
             },
                {
                    title: '操作',
                    align: 'center',
                    width: '160px',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
						if((range=='deal'||range=='start')&&row.shape!='end')
						{
							actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="deal(\'' + row.id + '\',\'' + row.wf_id + '\',\'' + row.node_id + '\',\'' + row.node_type + '\',\'' + row.detail_url + '\',\'' + row.detail_url_all + '\')"><i class="fa fa-floppy-o"></i> 处理</a> ');
						}
                       	actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="viewDetail(\'' + row.id + '\',\'' + row.wf_id + '\',\'' + row.node_id + '\',\'' + row.node_type + '\',\'' + row.detail_url + '\',\'' + row.detail_url_all + '\')">明细</a> ');

						actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="viewWf(\'' + row.id + '\',\'' + row.wf_id + '\',\'' + row.node_id + '\')"><i class="fa fa-picture-o"></i> 流程图</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="viewHis(\'' + row.id + '\',\'' + row.wf_id + '\',\'' + row.node_id + '\')">审批详情</a> ');
                        
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        
    	$("#bootstrap-table").colResizable({
    		liveDrag:true, 
			gripInnerHtml:"<div class='grip'></div>", 
			draggingClass:"dragging", 
            resizeMode:'overflow'
    	});
    });
    
    function viewDetail(task_id,wf_id,node_id,node_type,detail_url,detail_url_all)
    {
    	var url = "#(ctx)/"+detail_url+"?id="+task_id+"&task_id="+task_id+"&m_id="+task_id+"&dotype=view";
    	if(detail_url.indexOf("?")>0)
		{
    		url = "#(ctx)/"+detail_url+"&id="+task_id+"&task_id="+task_id+"&m_id="+task_id+"&dotype=view";
		}
		else
		{
			url = "#(ctx)/"+detail_url_all+"?id="+task_id+"&task_id="+task_id+"&m_id="+task_id+"&dotype=view";
		}
    	
        
    	showWinFull('流程明细',url); //注意第二个参数
    }

    function viewWf(task_id,wf_id,node_id)
    {
    	var url = "#(ctx)/jwflow_view?task_id="+task_id+"&wf_id="+wf_id+"&node_id="+node_id;
    	showWinFull('流程查看',url); //注意第二个参数
    }
    
    function viewHis(task_id,wf_id,node_id)
    {
    	var url = "#(ctx)/jwflow_view/history?task_id="+task_id+"&wf_id="+wf_id+"&node_id="+node_id;
    	
    	showWinFull('审批详情',url); //注意第二个参数
    }

	function deal(task_id,wf_id,node_id,node_type,detail_url,detail_url_all)
	{
		var url = "#(ctx)/jwflow_deal?task_id="+task_id+"&wf_id="+wf_id+"&node_id="+node_id;
		window.location.href=url;
	}
</script>
</body>
#end
